#include <iostream>
#include "ioc.hpp"

class ICar {
public:
	virtual void run() = 0;
	~ICar() {
		std::cout << "car destory...\n";
	}
};

class Bus : public ICar {
public:
	Bus(std::string name) :_name(name) { }
	void run() override {
		std::cout << "Bus " << _name << " run \n";
	}
private:
	std::string _name;
};

class Tank : public ICar {
public:
	void run() override {
		std::cout << "Tank run...\n";
	}
	
};

class Driver {
public:
	Driver(ICar* car) :_car(car) { }
	~Driver() {
		std::cout << "Driver destory...\n";
		delete _car;
	}
	void run() {
		std::cout << "Driver: ";
		_car->run();
	}
private:
	ICar* _car;
};

int main() {
	try {
		IocContainer ioc;
		ioc.registerType<ICar, Bus, std::string>("bus");
		ioc.registerType<ICar, Tank>("tank");
		ioc.registerType<Driver, Tank>("vec");

		// ========================

		auto car = ioc.resolveShared<ICar, std::string>("bus", "Dong Feng");
		car->run();

		auto driver = ioc.resolveShared<Driver>("vec");
		driver->run();
	}
	catch (const std::exception& e) {
		std::cout << e.what() << std::endl;
	}
	std::cin.get();
	return 0;
}




